package com.formulas.certification.oauth.executor.query;

import cn.hutool.core.collection.CollectionUtil;
import com.formulas.certification.domain.oauth.gateway.OauthClientDetailsGateway;
import com.formulas.certification.domain.oauth.model.OauthClientDetailsEntity;
import com.formulas.certification.dto.OauthClientDetailsQry;
import com.formulas.certification.dto.data.OauthClientDetailsDTO;
import com.formulas.certification.oauth.convertor.OauthClientDetailsConvertor;
import com.formulas.component.dto.PageResponse;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yiwannuofulasi
 * @date 2023/6/15 11:58
 */
@Component
public class OauthClientDetailsQryExe {

    @Resource
    private OauthClientDetailsGateway oauthClientDetailsGateway;

    public PageResponse<OauthClientDetailsDTO> execute(OauthClientDetailsQry qry) {
        List<OauthClientDetailsEntity> oauthClientDetailsEntityList =
                oauthClientDetailsGateway.queryOauthClientDetailsPageList(qry);
        if (CollectionUtil.isEmpty(oauthClientDetailsEntityList)){
            return PageResponse.of(null, 0, qry.getPageSize(), qry.getPageIndex());
        }
        List<OauthClientDetailsDTO> dtoList = OauthClientDetailsConvertor.INSTANCE.toOauthClientDetailsDTOList(oauthClientDetailsEntityList);
        return PageResponse.of(dtoList, dtoList.size(), qry.getPageSize(), qry.getPageIndex());
    }
}
